package com.yh.csx.crm.service;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yh.csx.crm.core.entity.Pagination;
import com.yh.csx.crm.core.util.BeanUtils;
import com.yh.csx.crm.dao.ApprovalCompletedMapper;
import com.yh.csx.crm.dao.ApprovalMapper;
import com.yh.csx.crm.dao.CustomerMapper;
import com.yh.csx.crm.po.Approval;
import com.yh.csx.crm.po.ApprovalCompleted;
import com.yh.csx.crm.po.Customer;
import com.yh.csx.crm.service.request.AppCustomerNoReq;
import com.yh.csx.crm.service.response.*;
import com.yh.csx.crm.service.vo.PageWrap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AppNotExamineService {
    @Autowired
    CustomerMapper customerMapper;
    @Autowired
    ApprovalCompletedMapper approvalCompletedMapper;

    @Autowired
    ApprovalMapper approvalMapper;


    public AppCreditBigCustInfoResp getCustomerInfo(Customer customer) {
        Customer cut = customerMapper.selectBycustomerNumber(customer);
        AppCreditBigCustInfoResp appCustomerResp = BeanUtils.convert(AppCreditBigCustInfoResp.class, cut);
        return appCustomerResp;
    }

    /**
     * 审核详情-拒绝弹框
     *
     * @param appr
     */
    public void insetCreditInfo(ApprovalCompleted appr) {
        appr.setCreateTime(new Date());
        //先查改审批
        approvalCompletedMapper.insert(appr);
    }

    /**
     * 本节点审核详情
     *
     * @param approval
     * @return
     */
    public AppNodeInfoResp selectNode(Approval approval) {
        //
        String string = approvalMapper.selcetStatus(approval);

        AppNodeInfoResp app = new AppNodeInfoResp();
        app.setCurrentNodeCode(string);
        return app;
    }

    public AppProcessInfoResp selectProcess(Approval approval) {
        //
        Approval appro = approvalMapper.selectProcess(approval);

        AppProcessInfoResp appCustomerResp = BeanUtils.convert(AppProcessInfoResp.class, appro);

        return appCustomerResp;
    }

    public PageWrap<AppCustomerNoResp> customeNot(Long userId,String customerStatus1,String customerStatus2,Pagination pagination){
        Page<Object> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
        List<Customer> list =  customerMapper.selectCustomeNot(userId,customerStatus1,customerStatus2);
        PageWrap pageWrap = new PageWrap();
        pageWrap.setResult(list);
        return pageWrap;
    }

}
